import os

def get_dir_size(dir,size_list=[]):

    try:
        dlist = os.listdir(dir)

        for f in dlist:

            file = os.path.join(dir, f)

            if os.path.isfile(file):
                f_size = os.path.getsize(file)
                size_list.append(f_size)
                return sum(size_list)

            if os.path.isdir(file):
                get_dir_size(file,size_list)

    except FileNotFoundError:
        print('目录路径无效，请重新输入！')


dir = input('请输入目录路径：')
s = get_dir_size(dir)
if s is not None:
    print('指定目录大小为：',s)

# /users/felicity/desktop/felicity

